package br.usp.icmc.client.dao;

import java.util.Iterator;
import java.util.List;

import br.usp.icmc.client.entidades.Client;



/************************************************************
 * @author felipe
 *
 * <b> <br> Projeto: Aplicativo Cliente <br><b>
 *
 * Classe de acesso a tabela Client
 * 
 *************************************************************/
public class ClientDAO extends HibernateAbstractDAO<Client, String>{

private int total;
	
	@Override
	public List<Client> select(String key) {
		// TODO Auto-generated method stub
		return null;
	}
		
	/***************************************************************
	 * Busca o cliente com e-mail e o password passado	 
	 *  
	 * @param email
	 * 			Email do login
	 * @param password
	 * 			Password do login
	 * @return
	 * 			Uma List com o nome do cliente
	 **************************************************************/
	public List login(String email, String password){
		return getSession().createQuery("from Client c where c.email='" + email + "' and c.password='" + password +"'").list();
	}
	
	
	/**
	 * Lista de clientes associado a um e-mail
	 * 
	 * @param email
	 * 		E-Mail do cliente
	 * @return
	 * 		Cliente associado ao e-mail
	 */
	public List cliente(String email){
		return getSession().createQuery("from Client c where c.email='" + email +"'").list();
	}
	
	/**
	 * Servicos contratados pelo Cliente
	 *  
	 * @param email
	 * 		E-mail do cliente
	 * @return
	 * 		Serviços do cliente
	 */
	public List selectServiceHired(String email){
		final String hql = "select distinct(hired) from Client as c inner join c.contractedServices as hired where c.email in (:email)";  
		  
		return getSession().createQuery(hql)     
				.setParameter("email", email)  
                .list();
	}
	
	/**
	 * Busca de todos os clientes
	 * 
	 * @return
	 *	Lista de clientes
	 */
	public List selectClients(){
		
		return getSession().createQuery("from Client c order by c.fullName").list();
	}
	
	
}
